package com.orange.interceptor;


import com.orange.commons.Constant;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Emp
 * @projectName: crm
 * @package: com.powernode.interceptor
 * @className: LoginInterceptor
 * @description: TODO
 * @date: 2021/11/30 11:22
 * @version: 1.0
 */
public class LoginInterceptor implements HandlerInterceptor {

    /**
     * 登录权限拦截
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //从Session中查询是否存在登录用户
        Object user = request.getSession().getAttribute(Constant.SESSION_USER_KEY);
        if (null!=user){
            return true;
        }
        response.sendRedirect(request.getServletContext().getContextPath()+"/login/toLogin.do");
        return false;
    }
}
